<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let time = '2019-7-24 12:6:23'  //2019年07月24日 12时06分23秒
        //方法一
        let a = time.replace('-', '年').replace('-', '月').replace(' ', '日 ').replace(':', '时').replace(':', '分') + '秒'


        //方案二  获取到年月日小时分钟秒这几个值
        let n = time.indexOf('-')
        let m = time.lastIndexOf('-')
        let x = time.lastIndexOf(' ')
        let y = time.indexOf(':')
        let z = time.lastIndexOf(':')
        let year = time.substring(0, n)
        let month = time.substring(n + 1, m)
        let day = time.substring(m + 1, x)
        let hour = time.substring(x + 1, y)
        let minute = time.substring(y + 1, z)
        let sec = time.substring(z + 1)
        console.log(`${year}年${month}月${day}日${hour}时${minute}分${sec}秒`);

        //方案三 split
        let q = time.split(' ')
        let w = q[0].split('-')
        let e = q[1].split(':')
        console.log(`${w[0]}年${w[1]}月${w[2]}日${e[0]}时${e[1]}分${e[2]}秒`);

        //方案四 正则
        let addZero = (val) => val < 10 ? '0' + val : val
        let ary = time.split(/(?: |-|:)/g)//['2019', '7', '24', '12', '6', '23']
        console.log(ary[0] + '年' + addZero(ary[1]) + '月' + ary[2] + '日' + ary[3] + '时' + addZero(ary[4]) + '分' + ary[5] + '秒');


    </script>
</body>

</html>